home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Miscellaneous
/
ival
/
error.c
< prev
next >
Wrap
Text File
|
1987-04-24
|
3KB
|
117 lines
/*
* error.c - error notification routines
*/
#include <quickdraw.h>
#include <memory.h>
#include <dialog.h>
#include <toolutil.h>
#include <syserr.h>
#include <packages.h>
#define ALTBOMB 401 /* Resource ID of our generic alert */
#define DISKSTRS 401 /* System error strings */
#define PROGSTRS 402 /* Program-specific error strings */
static short errstr[] = { /* string # to error-number mapping */
dirFulErr, dskFulErr, nsvErr, ioErr, bdNamErr,
fnOpnErr, eofErr, posErr, mFulErr, tmfoErr,
fnfErr, wPrErr, fLckdErr, vLckdErr, fBsyErr,
dupFNErr, opWrErr, paramErr, rfNumErr, gfpErr,
volOffLinErr, permErr, volOnLinErr, nsDrvErr, noMacDskErr,
extFSErr, fsRnErr, badMDBErr, wrPermErr, memFullErr
};
static char msg[256]; /* buffer for any text to put in an error alert */
/*
* diskerr() - given a system error number, notify the user of the error.
*/
diskerr(err)
OSErr err;
{
short sidx; /* index of the string to say */
/*
* find the index of the errstr[] entry that has the given error code,
* Then use that index as a Resource string number to fetch and print.
*/
for (sidx = 1; sidx <= sizeof(errstr) / sizeof(errstr[0]); ++sidx) {
if (errstr[sidx - 1] == err) break;
}
if (sidx <= sizeof(errstr) / sizeof(errstr[0])) {
GetIndString(msg, DISKSTRS, sidx);
} else {
NumToString((long) err, msg);
}
ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
(void) StopAlert(ALTBOMB, (ProcPtr) 0);
ResetAlrtStage();
}
/*
* progstop(), prognote(), progcaution() - given a string ID from
* the program's error strings,
* print that string inside a Stop, Note, or Caution alert.
*/
progstop(sidx) short sidx; { progmsg(sidx, stopIcon); }
prognote(sidx) short sidx; { progmsg(sidx, noteIcon); }
progcaution(sidx) short sidx; { progmsg(sidx, ctnIcon); }
/*
* progmsg() - server to progstop(), etc.
*/
static
progmsg(sidx, severity)
short sidx;
short severity;
{
GetIndString(msg, PROGSTRS, sidx);
ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
switch (severity) {
case stopIcon: (void) StopAlert(ALTBOMB, (ProcPtr) 0); break;
case noteIcon: (void) NoteAlert(ALTBOMB, (ProcPtr) 0); break;
case ctnIcon: (void) CautionAlert(ALTBOMB, (ProcPtr) 0); break;
}
ResetAlrtStage();
}
/*
* debugdlg() - (FOR DEBUG ONLY) display the given C string in an alert.
* This routine allows a primitive form of debugging via sprintf()'s.
*/
debugdlg(s)
char *s; /* C string */
{
(void) strcpy(msg, s);
ctop(msg);
ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
(void) StopAlert(ALTBOMB, (ProcPtr) 0);
}
/*
* saydialog() - show the user the given dialog.
*/
saydialog(dlgid)
short dlgid; /* Resource ID of the dialog to show */
{
short itemhit;
DialogPtr reportptr;
/*
* Get the dialog; NIL => use heap storage; -1 => make dlg frontmost.
* Wait for some item to be selected (OK is the only one),
* then free up the memory and erase the dialog.
*/
reportptr = GetNewDialog(dlgid, (char *) 0, (long) -1);
ModalDialog((ProcPtr) 0, &itemhit);
DisposDialog(reportptr);
}